package org.beetl.sql2o.tools;

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;

/**
 * Created with IntelliJ IDEA. User: lars Date: 6/14/13 Time: 12:02 AM To change
 * this template use File | Settings | File Templates.
 */
public class IOUtils {

 private static final int EOF = -1;
 private static final int DEFAULT_BUFFER_SIZE = 1024 * 4;

 public static byte[] toByteArray(InputStream input) throws IOException {
  ByteArrayOutputStream output = new ByteArrayOutputStream();
  byte[] buffer = new byte[DEFAULT_BUFFER_SIZE];
  long count = 0;
  int n = 0;
  while (EOF != (n = input.read(buffer))) {
   output.write(buffer, 0, n);
   count += n;
  }
  return output.toByteArray();
 }
}
